//
//  MYGAcademicReserveAlert.swift
//  MYDoctor
//
//  Created by Denny on 2024/5/27.
//

import UIKit
import BRPickerView

class MYGAcademicReserveAlert: UIView {

    var tapDismissCompletion:(()->Void)?
    var tapSureCompletion:(()->Void)?

    var keshiArr:[String] = []
    
    @IBOutlet weak var couresTF: UITextField!
    @IBOutlet weak var adddressTF: UITextField!
    @IBOutlet weak var coreTF: UITextField!
    
    @IBAction func tapSure(_ sender: Any) {
        if let c = tapSureCompletion {
            c()
        }
    }
    @IBAction func tapCancel(_ sender: Any) {
        if let c = tapDismissCompletion {
            c()
        }
    }
    
  
    @IBAction func slectHospital(_ sender: UIButton) {
        
        let vc = MYGHospitalViewController()
        vc.callHospitailName = {name in
            self.adddressTF.text = name
        }
        self.rootResponsder().navigationController?.pushViewController(vc, animated: true)
    }
    
    @IBAction func selectDepartment(_ sender: UIButton) {
        
        BRStringPickerView.showPicker(withTitle: "请选择科室", dataSourceArr: self.keshiArr, select: 0) {[self] item in
            self.couresTF.text = item?.value ?? ""

        }
        
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        getHosAndSub()
    }
    
    func getHosAndSub(){
        
        MMYGNetwork<MYGResumeApi, MYGSubjectListModel>.request(target: .getSubjectList(params: [:])) {[weak self] result in
            guard let items = result?.data else {
                return
            }
            for item in items {
                self?.keshiArr.append(item.label)
            }
        } failed: { _, error in
//            MYGLoading.hide()
//            MYGHUD.showToast(text: error)
        }
    }
}
